package com.taobao.message.api;

import com.taobao.base.model.RestResponse;
import com.taobao.base.utils.SecurityUtil;
import com.taobao.message.feignclient.UserServiceClient;
import com.taobao.message.model.dto.MsgPrevDto;
import com.taobao.message.model.po.Messages;
import com.taobao.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MessageController {


    @Autowired
    private MessageService messageService;


    /**
     * 获取消息预览列表
     */
    @GetMapping("getMessagePreviewList")
    public RestResponse<List<MsgPrevDto>> getMessagePreviewList() {

        //取出当前用户身份
        SecurityUtil.TbUser user = SecurityUtil.getUser();
        System.err.println(user);

        return messageService.getMessagePreviewList(user.getTbId());
    }

    /**
     * 根据双方id获取消息列表
     */
    @GetMapping("getMessageList/{friendId}")
    public RestResponse<List<Messages>> getMessageList(@PathVariable("friendId") String friendId) {
        //取出当前用户身份
        SecurityUtil.TbUser user = SecurityUtil.getUser();
        System.err.println(user);

        return messageService.getChatRecord(user.getTbId(), friendId);
    }

}
